package de.g18.llmaa.gui.workspace.internalFrame.product;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableColumn;

import de.g18.llmaa.logic.vos.VOProduct_Key;

public class JPanel_Product extends JPanel {

	private VOProduct_Key product;
	private JPanel jPanel_ProductInfo = null;
	private JScrollPane jScrollPane_KeyList = null; // @jve:decl-index=0:visual-constraint="442,145"
	private JButton jButton = null; // @jve:decl-index=0:visual-constraint="181,5"
	private JLabel jLabel = null;
	private JTextField jTextField_ProduktName = null;

	private JTable table_Keys;
	private TableModel_Keys tableModel_Keys;

	public JPanel_Product(VOProduct_Key product) {
		this.product = product;
		tableModel_Keys = new TableModel_Keys(product.getList_Key());
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 */
	private void initialize() {
		this.setLayout(new BorderLayout());
		this.setSize(new Dimension(311, 197));
		this.add(getJPanel_ProductInfo(), BorderLayout.NORTH);
		this.add(getJScrollPane_KeyList(), BorderLayout.CENTER);

	}

	/**
	 * This method initializes jPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel_ProductInfo() {
		if (jPanel_ProductInfo == null) {
			jPanel_ProductInfo = new JPanel();
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints2.gridy = 0;
			gridBagConstraints2.weightx = 1.0;
			gridBagConstraints2.gridx = 1;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			jLabel = new JLabel();
			jLabel.setText("Produkt Name:");
			
			jPanel_ProductInfo.setBorder(BorderFactory.createTitledBorder("Produkt Information"));
			jPanel_ProductInfo.setLayout(new GridBagLayout());

			jPanel_ProductInfo.add(jLabel, gridBagConstraints);
			jPanel_ProductInfo.add(getJTextField_ProduktName(),
					gridBagConstraints2);
		}
		return jPanel_ProductInfo;
	}

	/**
	 * This method initializes jScrollPane
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJScrollPane_KeyList() {
		if (jScrollPane_KeyList == null) {
			jScrollPane_KeyList = new JScrollPane();
			jScrollPane_KeyList.setBorder(BorderFactory.createTitledBorder("Lizenzen"));
			jScrollPane_KeyList.setViewportView(getTable_Keys());
		}
		return jScrollPane_KeyList;
	}

	/**
	 * This method initializes jTextField
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTextField_ProduktName() {
		if (jTextField_ProduktName == null) {
			jTextField_ProduktName = new JTextField();
			jTextField_ProduktName.setText(product.getProduct_Name());
			jTextField_ProduktName.setSize(450, 25);
			jTextField_ProduktName.setEditable(false);
			
		}
		return jTextField_ProduktName;
	}

	private JTable getTable_Keys() {
		if (table_Keys == null) {
			table_Keys = new JTable(tableModel_Keys);
			 // Disable auto resizing
			table_Keys.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
		    
			
			//Spaltenbreite Serial
		    int vColIndex = 2;
		    TableColumn col = table_Keys.getColumnModel().getColumn(vColIndex);
		    int width = 350;
		    col.setPreferredWidth(width);

			//Spaltenbreite Datum
		    col = table_Keys.getColumnModel().getColumn(1);
		    width = 100;
		    col.setPreferredWidth(width);
		    
			table_Keys.updateUI();
		}
		return table_Keys;
	}

} // @jve:decl-index=0:visual-constraint="10,10"
